package Test_2019_3_19.servlet;

import Test_2019_3_19.pojo.Attendance;
import Test_2019_3_19.util.JdbcUtil;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(name = "CountServlet", urlPatterns = {"/atb/count.do"})
public class CountServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 解决中文乱码
        response.setContentType("application/text; charset=utf-8");
        // 查询考勤状况
        JdbcUtil jdbc = new JdbcUtil();
        int[][] count = new int[5][5];
        for (int i = 1; i < 5; i++) {
            count[i][0] = jdbc.Count(i, "正常");
            count[i][1] = jdbc.Count(i, "迟到");
            count[i][2] = jdbc.Count(i, "早退");
            count[i][3] = jdbc.Count(i, "请假");
            count[i][4] = jdbc.Count(i, "旷课");
        }
//        for (int j = 1; j < 5; j++) {
//            System.out.println(count[j][0]);
//            System.out.println(count[j][1]);
//            System.out.println(count[j][2]);
//            System.out.println(count[j][3]);
//            System.out.println(count[j][4]);
//        }
        // (判断操作是否成功)转化json格式准备
        Map<String, Object> mjs = new HashMap<String, Object>();
        mjs.put("count", count);
        // 把数据转化为json格式
        String Json = JSON.toJSONString(mjs);
        response.getWriter().write(Json);
    }
}